package com.aat.dxfy.string;

import java.util.HashMap;
import java.util.Map;

public final class UrlStr {

	public static void main(String[] args) {
		String url = "http://www.abc.com/add.do?name=张三&age=26&app=sdk";

		System.out.println(queryStr2Map(url));
	}

	public static Map<String, String> queryStr2Map(String url) {
		Map<String, String> map = new HashMap<>();
		String queryStr = null;
		if (url.contains("?")) {
			int i = url.indexOf("?");
			queryStr = url.substring(i + 1, url.length());
			if (queryStr != null && queryStr.length() > 0) {
				if (queryStr.contains("&")) {
					String[] ss = queryStr.split("&");
					for (String s : ss) {
						if (s.contains("=")) {
							String[] kvs = s.split("=");
							if (kvs != null && kvs.length == 2) {
								if (kvs[0] != null && kvs[1] != null) {
									map.put(kvs[0], kvs[1]);
								}
							}
						}
					}
				} else {
					if (queryStr.contains("=")) {
						String[] kvs = queryStr.split("=");
						if (kvs != null && kvs.length == 2) {
							if (kvs[0] != null && kvs[1] != null) {
								map.put(kvs[0], kvs[1]);
							}
						}
					}
				}
			}
		}

		return map;
	}

}
